package utils

import (
	"context"
	"crypto/md5"
	"encoding/hex"
	"fmt"
	"ksirGo/global"
	"time"
)

var ctx = context.Background()

func GetNowDateStr() string {
	now := time.Now()
	dateStr := fmt.Sprintf("%02d-%02d-%02d", now.Year(), int(now.Month()), now.Day())
	return dateStr
}

func md5plus(str string, salt string, iteration int) string {
	b := []byte(str)
	s := []byte(salt)
	h := md5.New()
	h.Write(s)
	h.Write(b)
	var res []byte
	res = h.Sum(nil)
	for i := 0; i < iteration-1; i++ {
		h.Reset()
		h.Write(res)
		res = h.Sum(nil)
	}
	return hex.EncodeToString(res)
}
func GeneratePassword(target string) string {
	return md5plus(target, global.CONFIG.System.Salt, 3)
}
